import 'package:aio/aio.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:app/generated/app_strings.dart';
import 'package:app/src/http/bean/wroks/delivery_notice.dart';
import 'package:app/src/http/bean/wroks/special_clauses.dart';
import 'package:app/src/ui/route/works/public/items/ui_base.dart';
import 'package:app/src/ui/route/works/public/items/ui_card.dart';
import 'package:app/src/utils/image_path_utils.dart';

import '../../../../app_ui.dart';

///发货审核：特殊加工额外收费说明
class UiSpecialClausesDelivery {
  ///List<SpecialClauses>? 特殊加工
  static Widget build(BuildContext context, List<AmountExplain>? data) {
    if (StringUtils.isEmpty(data)) {
      return AppUi.getEmptyView();
    }
    List<Widget> children = [];
    children.add(UiBase.title(context, AppStrings.of(context).AmountExplainList,
        bottom: AppEdgeInsets.margin_bottom)); //标题
    children.add(_table(context, data));
    var column = UiBase.column(context, children);
    var card = UiCard.build(context, column);
    return card;
  }

  static Widget _table(BuildContext context, List<AmountExplain>? data) {
    List<TableRow> children = [];
    //标题
    children.add(TableRow(
        //第一行，添加背景色
        decoration:
            BoxDecoration(color: AppColors.backgroundColorWithTableTitle),
        children: [
          Center(
            child: _text(AppStrings.of(context).TheSerial), //序号
          ),
          Center(
            child: _text(AppStrings.of(context).Acount), //金额
          ),
          Center(
            child: _text(AppStrings.of(context).Unit), //单位
          ),
          Center(
            child: _text(AppStrings.of(context).Intro), //备注
          ),
        ]));
    var serial = 1;
    if (data != null && data.length > 0) {
      data.forEach((element) {
        //内容
        children.add(TableRow(children: [
          Center(
            child: _text((serial++).toString()), //序号
          ),
          Center(
            child: _text(element.Acount), //金额
          ),
          Center(
            child: _text(element.Unit), //单位
          ),
          Center(
            child: _text(element.Intro), //备注
          ),
        ]));
      });
    }
    var table = Table(
      defaultVerticalAlignment: TableCellVerticalAlignment.middle,
      columnWidths: {
        0: FixedColumnWidth(50),
      },
      border: AppStyle.getTableBorder(),
      textDirection: TextDirection.ltr,
      children: children,
    );
    var width = 950.0;
    if (width < px.screenWidth()) {
      width = px.screenWidth();
    }
    return SingleChildScrollView(
      scrollDirection: Axis.horizontal,
      physics: BouncingScrollPhysics(),
      child: Container(
        width: width,
        child: table,
      ),
    );
  }

  static Widget _text(String? text, {bool isBlue = false}) {
    TextStyle? style = null;
    if (isBlue) {
      style = AppStyle.textStyleWithCardBlue();
    } else {
      style = AppStyle.textStyleWithCard();
    }
    return Text(
      text ?? "",
      style: style,
    );
  }
}
